﻿using System.Collections.Generic;
using System.Text;
using System.Web.UI;
using Ue.Infrastructure.RepositoryFramework;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Adver;

namespace Ue.Qcdz.UI.Controls.Adver
{
    public class JsAdView : SkinnedControl
    {
        private string skinFileName = "/Themes/zh-cn/Skins/Globals_IndexFlash.ascx";
        public string Src { get; set; }
        public string Url { get; set; }
        public string SplitString { get; set; }
        public string WebSiteName { get; set; }
        public string PageSiteName { get; set; }
        public string DivId { get; set; }



        #region Overrides of SkinnedControl
        private IAdvertisementRepository repository;
        protected override string GetSkinFileName()
        {
            return skinFileName;
        }
        private void GetPath()
        {

            List<string> arrSrc = new List<string>();
            List<string> arrUrl = new List<string>();
            StringBuilder strarrSplit = new StringBuilder();
            this.repository = RepositoryFactory.GetRepository<IAdvertisementRepository, Domain.Adver.Advertisement>();
            var listAd = repository.Find(WebSiteName, PageSiteName, DivId);
            foreach (var adItem in listAd)
            {
                arrSrc.Add(adItem.AdUrl);
                arrUrl.Add(adItem.AdLink);
                strarrSplit.Append("|");
            }
            Src = string.Join("|", arrSrc.ToArray());
            Url = string.Join("|", arrUrl.ToArray());
            SplitString = strarrSplit.ToString();
        }

        protected override void InitializeSkin(Control skin)
        {
            GetPath();
        }

        #endregion
    }
}
